<!--
 * @Author: wangding
 * @Date: 2020-11-03 18:00:58
 * @LastEditTime: 2021-02-20 13:59:36
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\device\inverter\remark.vue
-->
<template>
    <div>
        <el-dialog
        :title="$t('introduce')"
        :visible="newVisibleRemark"
        width="30%"
        @close="()=>{$store.commit('setNewVisibleRemark',false)}"
        :close-on-click-modal='false'
        >
        <el-form ref="form" :model="form" label-width="80px" >
            <el-row :gutter="20">
                <el-col :span="16" :offset="4">
                    <el-form-item :label="$t('introduce')" prop="note" :rules="[{ required: false, message: $t('index_js_notNull')}]">
                        <el-input v-model="form.note" :placeholder="$t('pleaseInput')"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="()=>{$store.commit('setNewVisibleRemark',false)}">{{$t('cancel')}}</el-button>
            <el-button type="primary" @click="save('form')">{{$t('sure')}}</el-button>
        </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    components: {

    },
    props: {
        remarkModalWifuSn:{
            type:String,
            default:''
        },
        remarkModalNote:{
            type:String,
            default:''
        },
    },
    data() {
        return {
            form:{
                note:''
            }
        };
    },
    computed: {
        newVisibleRemark(){
            return this.$store.state.sysStore.newVisibleRemark
        }
    },
    watch: {
        remarkModalNote:{
            handler(nv,ov){
                this.form.note = nv
            }
        }
    },
    created() {
        
    },
    mounted() {

    },
    methods: {
        async wifiInsertNote(){
            let res = await this.API.wifiInsertNote({
                wifiSN:this.remarkModalWifuSn,
                note:this.form.note
            })
            if(res.success){
                this.$message({
                message: this.$t('index.control_success'),
                type: 'success'
                });
                this.$emit('uploadData',true)
                this.$store.commit('setNewVisibleRemark',false)
            }else{
                this.$message({
                message: this.$t('index.control_fail'),
                type: 'warning'
                });
            }
        },
        save(formName){
            this.$refs[formName].validate((valid) => {
              if (valid) {
                  this.wifiInsertNote()
              } else {
                console.log('error submit!!');
                return false;
              }
            });
        },
    },
};
</script>

<style  lang="less" scoped>

</style>
